package com.example.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.example.model.dtos.PageResult;
import com.example.model.dtos.R;
import com.example.model.pojo.MaterialsLoss;
import com.example.model.pojo.OutForm;
import com.example.model.pojo.Warehouse;
import com.example.model.vo.MaterialsVo;
import com.example.service.InFormService;
import com.example.service.MaterialsService;
import com.example.service.OutFormService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 * 入库控制类
 */
@RestController
@RequestMapping("goods/goods/")
public class GoodsController {

    @Autowired(required = false)
    MaterialsService materialsService;

    @Autowired(required = false)
    OutFormService outFormService;

    @Autowired(required = false)
    InFormService inFormService;

    /**
     * 获取所有物资信息
     */
    @RequestMapping("getWarehouseList")
    public R<List<Warehouse>> getAllMaterialsVo(){
        List<Warehouse> warehouseList=materialsService.getWarehouse();
        return R.success(warehouseList);
    }

    /**
     * 更新库存
     */
    @RequestMapping("updateWarehouseList")
    public R<String> updateWarehouseList(@RequestBody List<Warehouse> warehouseList){
        Boolean flag = materialsService.updateWarehouseList(warehouseList);
        if (!flag){
            return R.error("更新失败");
        }
        return R.success("更新成功");
    }

    /**
     * 物资报损
     */
    @RequestMapping("MaterialsLoss")
    public R<String> MaterialsLoss(@RequestBody MaterialsLoss materialsLoss){

        Boolean flag = outFormService.MaterialsLoss(materialsLoss);
        if (!flag){
            return R.error("报损失败");
        }

        return R.success("报损成功");
    }

    @RequestMapping("get")
    public R<MaterialsLoss> MaterialsLoss(){

        MaterialsLoss materialsLoss = new MaterialsLoss();

        return R.success(materialsLoss);
    }

}
